package com.txunda.zhuohired.fgt.manage.home;

import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.ants.theantsgo.config.Settings;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.adapter.manage.home.ManageHomeListAdapter;
import com.txunda.zhuohired.adapter.user.home.CapacityAdapter;
import com.txunda.zhuohired.aty.manage.home.ManageResumeDetailsAty;
import com.txunda.zhuohired.base.BaseFgt;
import com.txunda.zhuohired.view.FlowLayout;
import com.txunda.zhuohired.view.TagAdapter;
import com.txunda.zhuohired.view.TagFlowLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/10 15:18
 * 功能描述：首页简历列表
 * 联系方式：jiahuanchen@126.com
 */

public class ManageHomeListFgt extends BaseFgt {
    /**
     * listView
     */
    @ViewInject(R.id.lv_manage_home_list)
    private ListView lv_manage_home_list;
    /**
     * 推荐
     */
    @ViewInject(R.id.ll_manage_home_list_capacity)
    private LinearLayout ll_manage_home_list_capacity;
    @ViewInject(R.id.lv_manage_home_list_capacity)
    private ListView lv_manage_home_list_capacity;
    @ViewInject(R.id.tv_manage_home_list_capacity_head)
    private TextView tv_manage_home_list_capacity_head;
    /**
     * 筛选
     */
    @ViewInject(R.id.ll_home_manege_list_screen)
    private LinearLayout ll_home_manege_list_screen;
    @ViewInject(R.id.tag_manage_home_list_screen_education)
    private TagFlowLayout tag_manage_home_list_screen_education;//学历
    @ViewInject(R.id.tag_manage_home_list_screen_suffer)
    private TagFlowLayout tag_manage_home_list_screen_suffer;//经验
    @ViewInject(R.id.tag_manage_home_list_screen_pay)
    private TagFlowLayout tag_manage_home_list_screen_pay;//薪水
    @ViewInject(R.id.tv_manage_home_list_screen_head)
    private TextView tv_manage_home_list_screen_head;

    @ViewInject(R.id.view_black)
    private View view_black;

    private List<String> tittleList;
    private int size;
    private List<String> capacityList;
    private String[] capacityStr = {"推荐", "最新"};
    private CapacityAdapter capacityAdapter;
    private int capacity = 0;
    private int initCapacity = 1;
    private List<String> sufferList;
    private final String[] suffer = {"无经验要求", "1年以内", "1-3年", "3-5年", "5年以上"};
    private List<String> educationList;
    private String[] educationStr = {"无学历要求", "小学", "初中", "高中", "中专", "大学", "本科及以上"};
    private List<String> screenPayList;
    private String[] screenPayStr = {"全部", "3K以下", "3K-5K", "5K-10K", "10K-20K", "50K及以上"};
    private int initScreen = 1;
    private int width;

    private ManageHomeListAdapter manageHomeListAdapter;

    @Override
    protected void immersionInit() {
        initView();
    }

    @Override
    @OnClick({R.id.tv_manage_home_list_screen_sure, R.id.ll_manage_home_list_capacity_head, R.id
            .ll_manage_home_list_screen_head, R.id.view_black})
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_manage_home_list_screen_sure://确定
                initClose();
                break;
            case R.id.view_black://关闭
                initClose();
                break;
            case R.id.ll_manage_home_list_capacity_head://推荐
                initCapacity = 2;
                initCapacity();
                break;
            case R.id.ll_manage_home_list_screen_head://筛选
                initScreen = 2;
                initScreen();
                break;

        }
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fgt_manage_home_list;
    }

    @Override
    protected void initialized() {
        capacityList = new ArrayList<>();
        for (int i = 0; i < capacityStr.length; i++) {
            capacityList.add(capacityStr[i]);
        }
        sufferList = new ArrayList<>();
        for (int i = 0; i < suffer.length; i++) {
            sufferList.add(suffer[i]);
        }
        educationList = new ArrayList<>();
        for (int i = 0; i < educationStr.length; i++) {
            educationList.add(educationStr[i]);
        }
        screenPayList = new ArrayList<>();
        for (int i = 0; i < screenPayStr.length; i++) {
            screenPayList.add(screenPayStr[i]);
        }
    }

    @Override
    protected void requestData() {
        initAdapter();
    }

    private void initAdapter() {
        manageHomeListAdapter = new ManageHomeListAdapter(getActivity());
        lv_manage_home_list.setAdapter(manageHomeListAdapter);
        lv_manage_home_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                startActivity(ManageResumeDetailsAty.class, null);
            }
        });
    }

    /**
     * 推荐
     */
    private void initCapacity() {
        view_black.setVisibility(View.VISIBLE);
        ll_manage_home_list_capacity.setVisibility(View.VISIBLE);
        ll_home_manege_list_screen.setVisibility(View.GONE);
        capacityAdapter = new CapacityAdapter(getActivity(), capacityList, capacity);
        lv_manage_home_list_capacity.setAdapter(capacityAdapter);
        capacityAdapter.SetClickListener(new CapacityAdapter.HolderClickListener() {
            @Override
            public void onHolderClick(int position) {
                capacity = position;
                tv_manage_home_list_capacity_head.setText(capacityList.get(position).toString());
                initClose();
            }
        });
    }

    /**
     * 筛选
     */
    private void initScreen() {
        view_black.setVisibility(View.VISIBLE);
        ll_manage_home_list_capacity.setVisibility(View.GONE);
        ll_home_manege_list_screen.setVisibility(View.VISIBLE);
        final LayoutInflater mInflater = LayoutInflater.from(getActivity());
        tag_manage_home_list_screen_education.setAdapter(new TagAdapter<String>(educationStr) {

            @Override
            public View getView(FlowLayout parent, int position, String s) {
                TextView tv = (TextView) mInflater.inflate(R.layout.tag_flow_layouttv,
                        tag_manage_home_list_screen_education, false);
                tv.setText(s);
                return tv;
            }
        });
        tag_manage_home_list_screen_suffer.setAdapter(new TagAdapter<String>(suffer) {

            @Override
            public View getView(FlowLayout parent, int position, String s) {
                TextView tv = (TextView) mInflater.inflate(R.layout.tag_flow_layouttv,
                        tag_manage_home_list_screen_suffer, false);
                tv.setText(s);
                return tv;
            }
        });
        tag_manage_home_list_screen_pay.setAdapter(new TagAdapter<String>(screenPayStr) {

            @Override
            public View getView(FlowLayout parent, int position, String s) {
                TextView tv = (TextView) mInflater.inflate(R.layout.tag_flow_layouttv,
                        tag_manage_home_list_screen_pay, false);
                tv.setText(s);
                return tv;
            }
        });
    }

    /**
     * 关闭
     */
    private void initClose() {
        controlType();
        view_black.setVisibility(View.GONE);
        ll_manage_home_list_capacity.setVisibility(View.GONE);
        ll_home_manege_list_screen.setVisibility(View.GONE);
    }

    /**
     * 控制三角
     */
    private void controlType() {
        Drawable nav_up1 = getResources().getDrawable(R.mipmap.icon_today_capacity_grey);
        nav_up1.setBounds(0, 0, nav_up1.getMinimumWidth(), nav_up1.getMinimumHeight());
        Drawable nav_up2 = getResources().getDrawable(R.mipmap.icon_today_capacity_blue);
        nav_up2.setBounds(0, 0, nav_up2.getMinimumWidth(), nav_up2.getMinimumHeight());
        Drawable nav_up3 = getResources().getDrawable(R.mipmap.icon_today_screen_address_blue);
        nav_up3.setBounds(0, 0, nav_up3.getMinimumWidth(), nav_up3.getMinimumHeight());
        Drawable nav_up4 = getResources().getDrawable(R.mipmap.icon_today_screen_address_grey);
        nav_up4.setBounds(0, 0, nav_up4.getMinimumWidth(), nav_up4.getMinimumHeight());
        if (initCapacity == 1) {
            tv_manage_home_list_capacity_head.setCompoundDrawables(null, null, nav_up1, null);
        } else if (initCapacity == 2) {
            tv_manage_home_list_capacity_head.setCompoundDrawables(null, null, nav_up2, null);
        }
        if (initScreen == 1) {
            tv_manage_home_list_screen_head.setCompoundDrawables(null, null, nav_up4, null);
        } else if (initScreen == 2) {
            tv_manage_home_list_screen_head.setCompoundDrawables(null, null, nav_up3, null);
        }
    }

    public static ManageHomeListFgt getFgt(List<String> tittleList, int size) {
        ManageHomeListFgt manageHomeListFgt = new ManageHomeListFgt();
        manageHomeListFgt.tittleList = tittleList;
        manageHomeListFgt.size = size;
        return manageHomeListFgt;
    }

    private void initView() {
        width = Settings.displayHeight / 2; // 计算控件宽度
        ViewGroup.LayoutParams lp = ll_manage_home_list_capacity.getLayoutParams();
        lp.width = Settings.displayWidth;
        lp.height = width;
        ll_manage_home_list_capacity.setLayoutParams(lp);
        ll_manage_home_list_capacity.setBackgroundColor(getResources().getColor(R.color.white));
        ViewGroup.LayoutParams lp1 = ll_home_manege_list_screen.getLayoutParams();
        lp1.width = Settings.displayWidth;
        lp1.height = width;
        ll_home_manege_list_screen.setLayoutParams(lp1);
    }
}
